package com.app.piemoment;

import java.util.ArrayList;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.app.piemoment.view.AddFileItems;

public class HelpActivity extends Activity {

	private ListView help_listview;
	private ImageView help_aboutus_iv, help_ask_iv, help_about_iv;
	private Button help_aboutus, help_ask, help_about;
	private ArrayList<Help> helpCStrings = new ArrayList<Help>();;
	private HelpAdpater helpAdpater;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.help);
		help_aboutus = (Button) findViewById(R.id.help_aboutus);

		help_aboutus.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				// help_aboutus_iv.setVisibility(View.VISIBLE);
				// help_ask_iv.setVisibility(View.INVISIBLE);
				// help_about_iv.setVisibility(View.INVISIBLE);
			}
		});
		help_ask = (Button) findViewById(R.id.help_ask);
		help_ask.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// help_aboutus_iv.setVisibility(View.INVISIBLE);
				// help_ask_iv.setVisibility(View.VISIBLE);
				// help_about_iv.setVisibility(View.INVISIBLE);
			}
		});
		help_about = (Button) findViewById(R.id.help_about);
		help_about.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// help_aboutus_iv.setVisibility(View.INVISIBLE);
				// help_ask_iv.setVisibility(View.INVISIBLE);
				// help_about_iv.setVisibility(View.VISIBLE);
			}
		});
		help_aboutus_iv = (ImageView) findViewById(R.id.help_aboutus_iv);
		help_ask_iv = (ImageView) findViewById(R.id.help_ask_iv);
		help_about_iv = (ImageView) findViewById(R.id.help_about_iv);
		help_listview = (ListView) findViewById(R.id.help_listview);

		helpCStrings
				.add(new Help(
						"1为什么这么久",
						"11国外啤酒厂商Big Boss Brewing为更好地宣传麾下产品，特意找来广告团队McKinney给自己定制了几台颇具创意的街机：它们都搭载有一款由McKinney原创的、名为《最后的酒吧战士》（The Last Barfighter）的2D横板格斗游戏，后者在玩法上类似《街霸》、《拳皇》等经典大作，但要说其的特色在于比赛胜出的玩家将会获得一杯Big Boss Brewing牌啤酒作为奖励——相当带感的做法有木有？"));
		helpCStrings
				.add(new Help(
						"2这么久为什么",
						"22因为专业 piemenment 国外啤酒厂商Big Boss Brewing为更好地宣传麾下产品，特意找来广告团队McKinney给自己定制了几台颇具创意的街机：它们都搭载有一款由McKinney原创的、名为《最后的酒吧战士》（The Last Barfighter）的2D横板格斗游戏，后者在玩法上类似《街霸》、《拳皇》等经典大作，但要说其的特色在于比赛胜出的玩家将会获得一杯Big Boss Brewing牌啤酒作为奖励——相当带感的做法有木有？"));

		helpCStrings
				.add(new Help(
						"3这么久为什么",
						"22因为专业 piemenment 国外啤酒厂商Big Boss Brewing为更好地宣传麾下产品，特意找来广告团队McKinney给自己定制了几台颇具创意的街机：它们都搭载有一款由McKinney原创的、名为《最后的酒吧战士》（The Last Barfighter）的2D横板格斗游戏，后者在玩法上类似《街霸》、《拳皇》等经典大作，但要说其的特色在于比赛胜出的玩家将会获得一杯Big Boss Brewing牌啤酒作为奖励——相当带感的做法有木有？"));

		helpCStrings
				.add(new Help(
						"4这么久为什么",
						"22因为专业 piemenment 国外啤酒厂商Big Boss Brewing为更好地宣传麾下产品，特意找来广告团队McKinney给自己定制了几台颇具创意的街机：它们都搭载有一款由McKinney原创的、名为《最后的酒吧战士》（The Last Barfighter）的2D横板格斗游戏，后者在玩法上类似《街霸》、《拳皇》等经典大作，但要说其的特色在于比赛胜出的玩家将会获得一杯Big Boss Brewing牌啤酒作为奖励——相当带感的做法有木有？"));

		helpAdpater = new HelpAdpater(helpCStrings);
		help_listview.setAdapter(helpAdpater);

	}

	class HelpAdpater extends BaseAdapter {
		private ArrayList<Help> helpCStrings = new ArrayList<Help>();;
		private LayoutInflater mInflater;

		public HelpAdpater(ArrayList<Help> helpCStrings) {
			this.mInflater = LayoutInflater.from(HelpActivity.this);
			this.helpCStrings = helpCStrings;
		}

		@Override
		public int getCount() {
			return helpCStrings.size();
		}

		@Override
		public Help getItem(int arg0) {
			return helpCStrings.get(arg0);
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		public final class ViewHolder {
			public ImageView img;
			public TextView title;
			public TextView info;
			public LinearLayout llLayout;
			public boolean isShow;
		}

		// AddFileItems afi = null;
		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {

			// holder = null;
			// if (convertView == null) {
			// holder = new HelpItemView(HelpActivity.this);
			// convertView = holder;
			// convertView.setTag(holder);
			// } else {
			// holder = (HelpItemView) convertView.getTag();
			// }
			// Help ssHelp = getItem(position);
			// holder.setContexts(ssHelp.title, ssHelp.cString);
			// holder.setOnClick(new OnClickListener() {
			//
			// @Override
			// public void onClick(View v) {
			// holder.changeStates();
			//
			// }
			// });
			//
			// return convertView;
			AddFileItems afi = null;
			if (convertView == null) {

				afi = new AddFileItems(HelpActivity.this);
				convertView = afi;
				convertView.setTag(afi);
			} else {
				afi = (AddFileItems) convertView.getTag();
			}

			final Help ssHelp = getItem(position);
			afi.holder.title.setText(ssHelp.title);
			afi.holder.info.setText(ssHelp.cString);
			if (position % 2 == 1) {
				afi.holder.llLayout.setBackgroundColor(Color
						.parseColor("#fffdec"));
			} else {
				afi.holder.llLayout.setBackgroundColor(Color
						.parseColor("#fff9d7"));
			}
			afi.holder.llLayout.setTag(afi);
			afi.holder.llLayout.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					AddFileItems afi = (AddFileItems) v.getTag();
					Log.e("HelpActivity", position + " / " + ssHelp.title
							+ " / " + ssHelp.cString);
					afi.holder.isShow = !afi.holder.isShow;
					if (afi.holder.isShow) {
						afi.holder.img
								.setBackgroundResource(R.drawable.jiantou2);
						afi.holder.info.setVisibility(View.VISIBLE);
					} else {
						afi.holder.img
								.setBackgroundResource(R.drawable.jiantou);
						afi.holder.info.setVisibility(View.GONE);
					}

				}
			});
			// holder.setContexts(ssHelp.title, ssHelp.cString);
			// holder.setOnClick(new OnClickListener() {

			return convertView;
		}
	}
}

class Help {
	public String title;
	public String cString;

	public Help(String title, String cString) {
		this.title = title;
		this.cString = cString;
	}

}
